package com.study.crypto.basic.kafka.consumer.listener;

import lombok.extern.slf4j.Slf4j;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.messaging.MessageHeaders;
import org.springframework.messaging.handler.annotation.Headers;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.stereotype.Component;

/**
 * @author Songjin
 * @since 2021-09-26 16:01
 */
@Slf4j
@Component
public class KafkaMessageConsumer {
    
    @KafkaListener(topics = {"${kafka.app.topic.foo}"})
    public void receive(@Payload String message, @Headers MessageHeaders headers) {
        log.info("KafkaMessageConsumer 接收到消息：{}", message);
        headers.keySet().forEach(key -> log.info("{}: {}", key, headers.get(key)));
    }
    
}